package com.bawei.mallshop.splash


import android.os.Bundle
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.common.mvi.BaseActivity
import com.bawei.ctrip.databinding.ActivitySplashBinding
import com.blankj.utilcode.util.LogUtils
import kotlinx.coroutines.launch

/**
 * @author ZhangRuiPeng
 * @description:
 */
class SplashAvtivity : BaseActivity<ActivitySplashBinding,SplashViewModel>(){
    override fun createViewBinding(): ActivitySplashBinding {
        return ActivitySplashBinding.inflate(inflater)
    }

    override fun createViewModel(): SplashViewModel {
        return ViewModelProvider(this).get(SplashViewModel::class.java)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        vm.requestToken()//进入界面获取对应token

    }

    override fun bindUiState() {

        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED){
                vm.realContainer.uiState.collect{
                    LogUtils.e("收集数据"+it.timeStr)
                    if (it.tokenState){
                        LogUtils.e(it.tokenEntity.token)
                        vm.startTimmer()
                    }
                    if (it.timeState){
                        LogUtils.e("收集数据"+it.timeStr)
                        v.tv.text = it.timeStr+"s"
                    }
                }
            }
        }

    }
























}